package com.by.yz.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.by.yz.common.ViewHolder;

import java.util.List;

/**
 * Created by mrs yang on 2016/10/26.
 */
public abstract class CommonAdapter<T> extends BaseAdapter {
    protected Context mcontext;
    protected List<T> mdata;
    protected int mlayoutId;
    public  CommonAdapter(Context context,List<T> data,int layoutId){
        mcontext=context;
        mdata=data;
        mlayoutId=layoutId;
    }
    @Override
    public int getCount(){
        return mdata.size();
    }
    @Override
    public T getItem(int i){
        return mdata.get(i);
    }
    @Override
    public long getItemId(int i){
        return i;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = ViewHolder.getHolder(mcontext,convertView,mlayoutId,parent,position);
        convert(holder,position);
        return holder.getmConvertView();
    }

    /**
     * get holder convert4
     */
    public abstract void convert(ViewHolder holder,int position);

}
